//package com.tencent.sr.iris.basic.saas.service.asynctask;
//
//import cn.hutool.core.collection.CollUtil;
//import com.tencent.sr.iris.activity.interfaces.request.group.GroupTaskRequest;
//import com.tencent.sr.iris.activity.interfaces.response.group.GroupTaskBoardResponse;
//import com.tencent.sr.iris.basic.saas.service.dependency.IrisGroupTaskBoardDependency;
//import com.tencent.sr.iris.basic.saas.service.model.GroupTaskBoardExportInfo;
//import com.tencent.sr.rmall.common.request.PaginationRequest;
//import com.tencent.sr.rmall.common.response.PaginationResponse;
//import com.tencent.sr.rmall.material.interfaces.enums.ETaskBusinessType;
//import com.tencent.sr.rmall.material.interfaces.response.TaskRecordResponse;
//import com.tencent.sr.rmall.springbootstarter.elasticjob.TaskJob;
//import com.tencent.sr.uma.code.saas.ExportAble;
//import com.tencent.sr.uma.code.saas.ScrollRequest;
//import com.tencent.sr.uma.code.saas.ScrollResponse;
//import com.tencent.sr.uma.code.saas.TaskContextHolder;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.concurrent.atomic.AtomicInteger;
//import javax.annotation.Resource;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Component;
//
//@TaskJob(jobName = "iris:export:ExportTestTask",cron = "0/5 * * * * ? ",shardingTotalCount = 1, description = "iris-export-test")
//@Component
//@Slf4j
//public class ExportTestTask extends BaseExportTask<GroupTaskRequest, GroupTaskBoardExportInfo> {
//
//    private static ThreadLocal<AtomicInteger> lineNum = ThreadLocal.withInitial(AtomicInteger::new);
//    private final int maxLines = 5000;
//    private final int pageSize = 50;
//
//    @Resource
//    private IrisGroupTaskBoardDependency irisGroupTaskBoardDependency;
//
//    @Override
//    public ScrollResponse<GroupTaskBoardExportInfo> get(ScrollRequest<GroupTaskRequest> scrollRequest) {
//        TaskRecordResponse taskRecord = TaskContextHolder.get();
//        log.info("taskRecord: {}, request: {}", taskRecord, scrollRequest);
//        ScrollResponse<GroupTaskBoardExportInfo> result = new ScrollResponse<>();
//        // 判断是否已经达到文件行数上限
//        AtomicInteger num = lineNum.get();
//        if (num.get() >= maxLines) {
//            lineNum.set(new AtomicInteger());
//            return result;
//        }
//        PaginationRequest<GroupTaskRequest> paginationRequest = new PaginationRequest<>();
//        GroupTaskRequest queryCriteria = scrollRequest.getQueryCriteria();
//        paginationRequest.setQueryCriteria(queryCriteria);
//        int pageNum = (num.get()) / pageSize + 1;
//        paginationRequest.setPageNum(pageNum);
//        paginationRequest.setPageSize(pageSize);
//        PaginationResponse<GroupTaskBoardResponse> response = irisGroupTaskBoardDependency
//                .groupTaskBoardExport(paginationRequest);
//        log.info("ExportAsyncTask response:{}", response);
//        List<GroupTaskBoardExportInfo> exportInfoList = new ArrayList<>();
//        if (response != null && CollUtil.isNotEmpty(response.getDataList())) {
//            for (GroupTaskBoardResponse boardResponse : response.getDataList()) {
//                GroupTaskBoardExportInfo groupTaskBoardExportInfo = new GroupTaskBoardExportInfo();
//                // 数据转换
//                groupTaskBoardExportInfo.readFromSearchResponseData(boardResponse);
//                // 设置行号
//                groupTaskBoardExportInfo.setNum(num.incrementAndGet());
//                exportInfoList.add(groupTaskBoardExportInfo);
//                // 最多支持5000条商品数据导出
//                if (num.get() >= maxLines) {
//                    break;
//                }
//            }
//            result.setDataList(exportInfoList);
//            // 最后一页
//            if (response.getDataList().size() < pageSize) {
//                num.addAndGet(pageSize - response.getDataList().size());
//            }
//        } else {
//            lineNum.set(new AtomicInteger());
//        }
//        result.setScrollId(String.valueOf(System.currentTimeMillis()) + exportInfoList.size());
//        log.info("ExportAsyncTask result:{}", result);
//        return result;
//    }
//
//    @Override
//    public String exportType() {
//        return ETaskBusinessType.IRIS_GROUP_BOARD.name();
//    }
//}
